﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Orf.Model;
using System.Windows.Forms;

namespace Orf.dto
{
    public class tuiFeiDAO
    {
        SqlHelper sqlhelper = null;
        public tuiFeiDAO()
        {
            sqlhelper = new SqlHelper();
        }

        /// <summary>
        /// 传入发票号码，类型为1时：获取病人姓名；为2时，获取这个病人的所有处方
        /// </summary>
        /// <param name="cf01Class"></param>
        /// <param name="intType"></param>
        /// <returns></returns>
        public DataTable Get_TuifeiInfo(MZ_CF01 cf01Class,int intType)
        {
            DataTable dt = null;    
            try
            {
                string strSql = "pro_Tuifei_fphm";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@fphm",cf01Class.fPHM),
                new SqlParameter("@intType",intType)};
                dt = new DataTable();
                dt = sqlhelper.ExecuteQuery(strSql, paras, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            return dt;
        }

        public void Update_Cf01(MZ_CF01 cf01Class)
        {
            int res = 0;
            try
            {
                string strSql = "update mz_cf01 set zfpb='1' where fphm=@fphm and cfhm=@cfhm";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@fphm",cf01Class.fPHM),
                     new SqlParameter("@cfhm",cf01Class.cFHM)
                };
                res = sqlhelper.ExecuteNonQuery(strSql, paras, CommandType.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            if (res >= 0)
            {
                return;
            }
            else
            {
                MessageBox.Show("处方作废成功！");
            }
        }

        public int Update_Sfmx(MZ_SFMX sfmxClass)
        {
            int res = 0;
            try
            {
                string strSql = "update mz_sfmx set zfpb='1' where fphm=@fphm and sfxm=@sfxm";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@fphm",sfmxClass.fPHM),
                     new SqlParameter("@sfxm",sfmxClass.sFXM),
                };
                res = sqlhelper.ExecuteNonQuery(strSql, paras, CommandType.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            return res;
        }
    }
}
